﻿using System;
using System.Collections;
using System.Text;

namespace MvcForum.Net.Business
{
    public class AccessMask
    {
        private readonly Hashtable _properties;

      //  private readonly Dictionary<string, object> _properties;

        public AccessMask()
        {
            _properties = new Hashtable();
        }

        public Hashtable Properties
        {
            get { return _properties; }

        }

        public bool IsAdmin
        {

            get
            {
                return Convert.ToBoolean(Properties["IsAdmin"]);

            }
            set
            {
                Properties["IsAdmin"] = value;


            }
        }



        #region Post Options


        public bool PostNewTopics
        {
            get
            {
                return Convert.ToBoolean(Properties["PostNewTopics"]);
            }
            set
            {
                Properties["PostNewTopics"] = value;

            }
        }

        public bool PostReplyToTopics
        {
            get
            {
                return Convert.ToBoolean(Properties["PostReplyToTopics"]);
            }
            set
            {
                Properties["PostReplyToTopics"] = value;

            }
        }


        public bool PostNewPolls
        {
            get
            {
                return Convert.ToBoolean(Properties["PostNewPolls"]);
            }
            set
            {
                Properties["PostNewPolls"] = value;

            }
        }

        public bool PostReplyPolls
        {
            get
            {
                return Convert.ToBoolean(Properties["PostReplyPolls"]);
            }
            set
            {
                Properties["PostReplyPolls"] = value;

            }
        }


        public bool VoteWithinPolls
        {
            get
            {
                return Convert.ToBoolean(Properties["VoteWithinPolls"]);
            }
            set
            {
                Properties["VoteWithinPolls"] = value;

            }
        }


        public bool PostWithinLockedForums
        {
            get
            {
                return Convert.ToBoolean(Properties["PostWithinLockedForums"]);
            }
            set
            {
                Properties["PostWithinLockedForums"] = value;

            }
        }

        public bool PostWithinLockedTopics
        {
            get
            {
                return Convert.ToBoolean(Properties["PostWithinLockedTopics"]);
            }
            set
            {
                Properties["PostWithinLockedTopics"] = value;

            }
        }

        #endregion

        #region Edit Options

        public bool EditOwnTopics
        {
            get
            {
                return Convert.ToBoolean(Properties["EditOwnTopics"]);
            }
            set
            {
                Properties["EditOwnTopics"] = value;

            }
        }

        public bool EditOwnPosts
        {
            get
            {
                return Convert.ToBoolean(Properties["EditOwnPosts"]);
            }
            set
            {
                Properties["EditOwnPosts"] = value;

            }
        }
        public bool EditOtherMembersTopics
        {
            get
            {
                return Convert.ToBoolean(Properties["EditOtherMembersTopics"]);
            }
            set
            {
                Properties["EditOtherMembersTopics"] = value;

            }
        }

        public bool EditOtherMembersPosts
        {
            get
            {
                return Convert.ToBoolean(Properties["EditOtherMembersPosts"]);
            }
            set
            {
                Properties["EditOtherMembersPosts"] = value;

            }
        }

        public bool ViewLastEditedByLabel
        {
            get
            {
                return Convert.ToBoolean(Properties["ViewLastEditedByLabel"]);
            }
            set
            {
                Properties["ViewLastEditedByLabel"] = value;

            }
        }

        public bool UpdateLastEditedBy
        {
            get
            {
                return Convert.ToBoolean(Properties["UpdateLastEditedBy"]);
            }
            set
            {
                Properties["UpdateLastEditedBy"] = value;

            }
        }

        #endregion

        #region Delete Options

        public bool DeleteOwnTopics
        {
            get
            {
                return Convert.ToBoolean(Properties["DeleteOwnTopics"]);
            }
            set
            {
                Properties["DeleteOwnTopics"] = value;

            }
        }

        public bool DeleteOwnPosts
        {
            get
            {
                return Convert.ToBoolean(Properties["DeleteOwnPosts"]);
            }
            set
            {
                Properties["DeleteOwnPosts"] = value;

            }
        }

        public bool DeleteOtherMembersTopics
        {
            get
            {
                return Convert.ToBoolean(Properties["DeleteOtherMembersTopics"]);
            }
            set
            {
                Properties["DeleteOtherMembersTopics"] = value;

            }
        }
        public bool DeleteOtherMembersPosts
        {
            get
            {
                return Convert.ToBoolean(Properties["DeleteOtherMembersPosts"]);
            }
            set
            {
                Properties["DeleteOtherMembersPosts"] = value;

            }
        }

        #endregion


        #region Topics & Forum options

        public bool AllowReadForums
        {

            get
            {
                return Convert.ToBoolean(Properties["AllowReadForums"]);

            }
            set
            {
                Properties["AllowReadForums"] = value;


            }
        }

        public bool AllowReadTopics
        {

            get
            {
                return Convert.ToBoolean(Properties["AllowReadTopics"]);

            }
            set
            {
                Properties["AllowReadTopics"] = value;


            }
        }


        public int MaxPollAnswers
        {
            get
            {
                return Convert.ToInt32(Properties["AllowReadTopics"]);

            }
            set
            {
                Properties["AllowReadTopics"] = value;

            }
        }




        #endregion

        #region Moderate Options

        



        public bool AllowPriority
        {
            get
            {
                return Convert.ToBoolean(Properties["AllowPriority"]);
            }
            set
            {
                Properties["AllowPriority"] = value;

            }
        }


        public bool AlwaysPostAprroved
        {
            get
            {
                return Convert.ToBoolean(Properties["AlwaysPostAprroved"]);
            }
            set
            {
                Properties["AlwaysPostAprroved"] = value;

            }
        }

        public bool QueueEdited
        {
            get
            {
                return Convert.ToBoolean(Properties["QueueEdited"]);
            }
            set
            {
                Properties["QueueEdited"] = value;
            }

        }


        #endregion


        #region Attachment Options
        public int UploadSize
        {
            get
            {
                return Convert.ToInt32(Properties["UploadSize"]);
                
            }
            set
            {
                Properties["UploadSize"] = value;
            }
        }


        public bool AllowFileManager
        {
            get
            {
                return Convert.ToBoolean(Properties["AllowFileManager"]);
            }
            set
            {
                Properties["AllowFileManager"] = value;
            }

        }
        


        public bool AllowDownloadAttachments
        {
            get
            {
                return Convert.ToBoolean(Properties["AllowDownloadAttachments"]);
            }
            set
            {
                Properties["AllowDownloadAttachments"] = value;
            }

        }
        

        #endregion

        #region Search Options

        public bool ViewSearch
        {
            get
            {
                return Convert.ToBoolean(Properties["ViewSearch"]);
            }
            set
            {
                Properties["ViewSearch"] = value;

            }
        }

        public int MaxSearchResults
        {
            get
            {
                return Convert.ToInt32(Properties["MaxSearchResults"]);
            }
            set
            {
                Properties["MaxSearchResults"] = value;

            }
        }


        public int MaxSearchKeywordLength
        {
            get
            {
                return Convert.ToInt32(Properties["MaxSearchKeywordLength"]);
            }
            set
            {
                Properties["MaxSearchKeywordLength"] = value;

            }
        }

        public int SearchResultsPerPage
        {
            get
            {
                return Convert.ToInt32(Properties["SearchResultsPerPage"]);
            }
            set
            {
                Properties["SearchResultsPerPage"] = value;

            }
        }





        #endregion


        #region Email Options


        public bool SendEmails
        {
            get
            {
                return Convert.ToBoolean(Properties["SendEmails"]);
            }
            set
            {
                Properties["SendEmails"] = value;

            }
        }

        public int MaxEmailRecipients
        {
            get
            {
                return Convert.ToInt32(Properties["MaxEmailRecipients"]);
            }
            set
            {
                Properties["MaxEmailRecipients"] = value;

            }
        }



        #endregion


        public override string ToString()
        {

            IDictionaryEnumerator _ie = Properties.GetEnumerator();



            var _sb = new StringBuilder();
            int i = 0;
            while (_ie.MoveNext())
            {

                _sb.AppendFormat("{0}:{1}", _ie.Key, _ie.Value);
                if (i != 0)
                    _sb.Append(",");

                i++;

            }

            return _sb.ToString();

        }

        public void LoadFromString(string _value)
        {

            if (!string.IsNullOrEmpty(_value) && _value.IndexOf(",") > 0)
            {
                string[] _p1 = _value.Split(',');

                foreach (string _s in _p1)
                {
                    if (!string.IsNullOrEmpty(_s) && _s.IndexOf(":") > 0)
                    {
                        string[] _p2 = _s.Split(':');

                        Properties[_p2[0]] = _p2[1];
                    }

                }

            }

        }

    }
}
